home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright Cornell University 1986. All rights are reserved.
-
- emcursor.c routines handle tracking and clicking of the mouse.
-
- Buttons on the left side of the emulator are highlighted as the
- mouse moves over them, and flash when clicked; pointing the mouse
- at the '?' produces a list of button titles. Care has to be taken
- that emulator drawing is then disabled or clipped, depending on the
- drawing mode (direct or QuickDraw).
-
- While the mouse is within in the emulator screen area,
- the character at which the mouse points is underlined.
-
- Clicking on the "Shrink control" causes the whole window to shrink
- to icon size.
-
- Moire unfortunately does not post updateEvents before clearing the
- screen and returning control to the application, so
- updatewait() fails to prevent the dropping of little mouse turds.
-
- */
-
- #include <em.h>
-
- #include <cntldefs.h>
- #include <rcodes.h>
- #include <h19.h>
- #include <3270.h>
- #include <macdefs.h>
-
- #define TOPRMARG 438 /* don't allow top controls past this point */
-
- int wasinq2;
- int wasinq3;
- Point mouseloc;
-
- short labelshift; /* displaying 1-12 or 13-24? */
-
- short q3button; /* the q3 control that is highlighted */
- Rect q3highrect; /* highlighted rectangle of q3 control */
-
- GrafPtr q3labdrawn; /* q3 labels have been put up in this window */
- extern EventRecord myEvent;
- extern Rect q3highrect;
-
- /*
- * set cursor to different pointers and fiddle with buttons
- * and cursor tracking
- */
-
- #define NOWHERE 0
- #define INQ2 1
- #define INQ3 2
- #define INEMSCR 3
-
-
- maccursor(donttrack)
- short donttrack; /* don't track the cursor */
- {
- int where;
- WindowPtr frontwind;
-
- if (keywindow == NULL || mfbackground) {
- return;
- }
- frontwind = FrontWindow();
-
- where = NOWHERE;
- if (frontwind == keydp->textwindow) {
- extern CursHandle textcursor;
-
- SetPort(frontwind);
- GetMouse(&mouseloc);
- if (PtInRect(pass(mouseloc), &(*keydp->texthand)->viewRect) )
- SetCursor(*textcursor);
- else
- SetCursor(&arrow);
-
- if (cupdatewait(keydp)) {
- /* do nothing with the cursor */
- return;
- }
- SetPort(keydp->emwindow); /* set port so old highlights can be reset */
- }
- else if (frontwind == keydp->emwindow) {
- /* the emulator window is up */
- if (cupdatewait(keydp)) {
- /* do nothing with the cursor */
- return;
- }
-
- SetPort(frontwind);
- GetMouse(&mouseloc);
-
- if ( ((mouseloc.v > 0) && (mouseloc.v < keydp->bottommarg))
- && ((mouseloc.h > 0) && (mouseloc.h < keydp->rightmarg) )) {
- /* in em screen, do cursor tracking */
- where = INEMSCR;
- if (!bkrd_act) {
- if (keydp->notrackcurs) {
- /* do no cursor tracking, make sure mouse cursor blanked */
- where = NOWHERE;
- SetCursor(&arrow);
- }
- else {
- SetCursor(thecursor);
- if (!donttrack) {
- trackon = emcurstrack(&mouseloc);
- }
- }
- }
- }
- else {
- #ifdef WORONACURSOR
- if (!donttrack && mouseloc.h > -12 && mouseloc.h <= 0) {
- #else
- if (!donttrack && mouseloc.h > -12 && mouseloc.h < -3) {
- #endif
- KeyMap keyarray;
- short shift;
-
- keyarray[1] = 0; /* make sure it's clear */
-
- GetKeys(&keyarray);
- shift = keyarray[1] & 0x00000001L ? 12 : 0;
- /* the shift key is down, do 13-24 */
-
- if (mouseloc.v >= -5 && mouseloc.v < frontwind->portRect.bottom) {
- /* in quadrant 3, 12 controls exist to be highlighted */
- #ifndef WORONACURSOR
- SetCursor(&arrow);
- #endif
- check3controls(pass(mouseloc), shift);
- wasinq3 = TRUE;
- where = INQ3;
- if (q3labdrawn)
- /* make sure Shift key changes get attention */
- q3labels(shift);
- labelshift = shift;
- }
- else if (mouseloc.v > -29 && mouseloc.v < -5) {
- /* in the question mark box, draw the labels */
-
- where = INQ2;
- SetCursor(&arrow);
- if (!bkrd_act || q3labdrawn) {
- q3labels(shift);
- wasinq2 = TRUE;
- }
- labelshift = shift;
- }
- else
- SetCursor(&arrow);
-
- }
- else
- SetCursor(&arrow);
- }
- }
-
- /* now reset the old mode that was on previously, but NOT the current one */
- switch (where) {
- case NOWHERE: {
- if (trackon && !donttrack) {
- trackon = FALSE;
- InvertRect(&mouserect);
- }
- if (wasinq2) {
- wasinq2 = FALSE;
- blanklabels();
- }
- if (wasinq3) {
- wasinq3 = FALSE;
- reset3controls();
- }
- break;
- }
- case INQ2: {
- if (trackon && !donttrack) {
- trackon = FALSE;
- InvertRect(&mouserect);
- }
- if (wasinq3) {
- wasinq3 = FALSE;
- reset3controls();
- }
- break;
- }
- case INQ3: {
- if (trackon && !donttrack) {
- trackon = FALSE;
- InvertRect(&mouserect);
- }
- #ifdef NOLABELHANG
- /* erase labels when cursor in quadrant 3 button array */
- if (wasinq2) {
- wasinq2 = FALSE;
- blanklabels();
- }
- #endif
- break;
- }
- case INEMSCR: {
- if (wasinq2) {
- wasinq2 = FALSE;
- blanklabels();
- }
- if (wasinq3) {
- wasinq3 = FALSE;
- reset3controls();
- }
- break;
- }
- }
- }
-
-
- /*
- * Underline the character pointed to by the mouse cursor if there has
- * been a change in the mouse coordinates.
- * Return TRUE if the underline is on the screen, FALSE if not.
- *
- */
-
- emcurstrack(mouseloc)
- Point * mouseloc;
- {
- static Rect omouserect;
- static Point omouseloc;
-
- if ((mouseloc->v == omouseloc.v) && (mouseloc->h == omouseloc.h
- || keydp->lineheight == 0 || keydp->fontwidth == 0) ) {
- /* no change in mouse position or window not OK, do nothing */
- if (trackon)
- return(TRUE);
- else
- return(FALSE);
- }
-
- omouseloc.v = mouseloc->v;
- omouseloc.h = mouseloc->h;
-
- mouserect.top = mouseloc->v - (mouseloc->v % keydp->lineheight) + keydp->mrecttop + keydp->voffset;
- mouserect.left = mouseloc->h - (mouseloc->h % keydp->fontwidth) + keydp->hoffset;
-
- if (trackon &&
- (mouserect.top == omouserect.top)
- && (mouserect.left == omouserect.left) )
- /* no change in x,y, no need to redraw highlight, do nothing */
- return TRUE;
-
- mouserect.bottom = mouserect.top + keydp->mrectbot;
- mouserect.right = mouserect.left + keydp->fontwidth;
-
- if (trackon)
- InvertRect(&omouserect); /* blank old */
- InvertRect(&mouserect); /* set new */
-
- omouserect.top = mouserect.top;
- omouserect.left = mouserect.left;
- omouserect.bottom = mouserect.bottom;
- omouserect.right = mouserect.right;
- return(TRUE);
- }
-
-
- /* handle a mouse click in the emulator window */
-
- emmouseclick(where)
- Point * where;
- {
- /* otherwise we look for controls in the emulator window */
-
- if (cupdatewait(keydp)) {
- /* do nothing */
- return;
- }
-
- if (where->v < 0) {
- if (where->h > 0) {
- /* in quadrant 1, top buttons */
- if (!line25on(keydp))
- doq1controls(where);
- }
- }
- else if (where->v > 0) {
- if (where->h < 0) {
- /* in quadrant 3, 12 buttons, send string assoc. w/ button */
- doq3controls();
- }
- else if ( (where->h > 0) && (where->h < keydp->rightmarg) ) {
- /* in quadrant 4, h19 screen, do cursor motion for user */
- if (!keydp->notrackcurs) {
- h19curset();
- }
- }
- else {
- /* maybe the user is hitting the shrink button */
- if (PtInRect(pass(*where), &keydp->shrinkrect)) {
- int shrinkhigh;
- Rect shrect;
- Point shrinkmouse;
-
- shrect = keydp->shrinkrect;
- InsetRect(&shrect, -1, -1);
- InvertRect(&shrect);
- shrinkhigh = TRUE;
- while (StillDown()) {
- /* track the mouse until it goes up */
- GetMouse(&shrinkmouse);
- if (PtInRect(pass(shrinkmouse), &keydp->shrinkrect)) {
- if (!shrinkhigh) {
- shrinkhigh = TRUE;
- InvertRect(&shrect);
- }
- }
- else {
- if (shrinkhigh) {
- shrinkhigh = FALSE;
- InvertRect(&shrect);
- }
- }
- }
- if (shrinkhigh) {
- /* hide the emulator window, show the iconwindow */
- InvertRect(&shrect);
- shrinkwindow(keydp);
- }
- /* else just ignore */
- }
- }
- }
- }
-
- /* get controls for the 3rd & 4th quadrant from resources
- and incorporate them in dynamically allocated strings
-
- untyped controls = 0 - 127
- ASCII resource numbers = 128 - 255
- IBM resource numbers = 256 ->
- */
-
-
- controlinit(windptr, idnum)
- WindowPtr windptr;
- int idnum; /* first of 11 Control ID numbers */
- {
- ControlHandle * conptr;
- ControlHandle * conend;
- int lastright;
-
- /* height and skip size for the quadrant 3 controls */
- q3conth = 22;
- q3contskip = 7;
-
- if (idnum == 0)
- return;
- lastright = -3;
- conend = &emdp->q1controls[Q1BUTMAX];
- for (conptr = emdp->q1controls; conptr < conend; conptr++, idnum++) {
- if ( (*conptr = GetNewControl(idnum, windptr) ) == NULL)
- /* no control in resource */
- break;
-
- /* resize the controls so the text inside just fits */
- (**conptr)->contrlRect.left = lastright + 5;
-
- lastright = (**conptr)->contrlRect.right = (**conptr)->contrlRect.left +
- (**conptr)->contrlTitle.length * 6 + 8;
- if (lastright > TOPRMARG) {
- DisposeControl(*conptr);
- *conptr = NULL;
- break;
- }
- (**conptr)->contrlVis = TRUE;
- }
- emdp->controlschanged = TRUE;
- InvalRect(&emdp->toprect);
- }
-
-
- /* kills all controls in window, preventing drawing of blank controls */
-
- killcontrols(contwind)
- WindowPtr contwind;
- {
- Rect norect;
- RgnHandle oldclip;
-
- /* reset clip closed */
- oldclip = NewRgn();
- GetClip(oldclip);
- norect.top = 0;
- norect.left = 0;
- norect.bottom = 0;
- norect.right = 0;
- ClipRect(&norect);
-
- /* WARNING -- this kills ALL controls */
- KillControls(contwind);
-
- /* reset clip to its former value */
- SetClip(oldclip);
- DisposeRgn(oldclip);
- }
-
-
- hideq1controls()
- {
- ControlHandle * conptr;
-
- for (conptr = keydp->q1controls; *conptr != NULL; conptr++)
- HideControl(*conptr);
- }
-
-
-
- showq1controls()
- {
- ControlHandle * conptr;
-
- for (conptr = keydp->q1controls; *conptr != NULL; conptr++)
- ShowControl(*conptr);
- }
-
-
- /*
- * This routine either makes a selection range (if the mouse moves while it's
- * down) or finds the x,y location of the last cursor tracking rectangle
- * & issues cursor motion commands to get there.
- */
-
- h19curset()
- {
- int xloc; /* first click x location */
- int yloc; /* " for y */
- int nxloc;
- int nyloc;
- int oxloc;
- int oyloc;
- Point newmouse;
- int nomove = TRUE;
- long starttick;
- Boolean donttrack;
-
- if (keydp->lineheight == 0 || keydp->fontwidth == 0) {
- /* no divides / 0, please...*/
- return;
- }
-
- oyloc = yloc = mouserect.top / keydp->lineheight;
- oxloc = xloc = mouserect.left / keydp->fontwidth;
-
- keydp->selfirsttime = TRUE;
-
- donttrack = cupdatewait(keydp);
-
- if (doubleclick) {
- /* was embedded in "nomove" case, here it will be livelier */
-
- if (keydp->clickmacro != NULL) {
- /* if there's a macro defined for a double click, do it */
- struct token * tkptr;
- int actcount;
-
- /* add the macro acts to the action queue */
- HLock(keydp->clickmacro);
-
- tkptr = (struct token *) (*keydp->clickmacro + 4);
- actcount = (GetHandleSize(keydp->clickmacro) - 4) / 2;
-
- while (actcount-- > 0) {
- keyputaction(tkptr->class, tkptr->entry);
- tkptr++;
- }
-
- HUnlock(keydp->clickmacro);
-
- bkrd_token_service(); /* execute the macro NOW */
- }
- }
- starttick = cticks + clickdelay;
- while (myEvent.modifiers != shiftKey && starttick > cticks)
- /* wait 1/6 sec to verify the user really wants to do a selection range */
- ;
-
- while (StillDown()) {
- /* highlight selection range for copy */
-
- if (keydp->selfirsttime) {
- if ( (myEvent.modifiers == shiftKey) || doubleclick) {
- /* the user wants to set a selection range from the cursor */
-
- if (trackon && !donttrack) {
- InvertRect(&mouserect); /* blank old track rectangle */
- trackon = FALSE;
- }
-
- keydp->selfirsttime = FALSE;
- nomove = FALSE;
- if (!keydp->selrectset) {
- /* set beginning point */
- keydp->selystart = keydp->ypos;
- keydp->selxstart = keydp->xpos;
- keydp->selyend = keydp->ypos;
- keydp->selxend = keydp->xpos;
- selmake(yloc, xloc);
- }
- else
- seladd(yloc, xloc);
- }
- else {
- if (keydp->selrectset)
- /* clear any existing selection */
- selreset(keydp);
-
- /* set beginning point at first point */
- keydp->selystart = yloc;
- keydp->selxstart = xloc;
- keydp->selyend = yloc;
- keydp->selxend = xloc;
- }
- keydp->selfirsttime = FALSE;
- }
-
- GetMouse(&newmouse);
- nyloc = newmouse.v / keydp->lineheight;
- nxloc = newmouse.h / keydp->fontwidth;
-
- /* fix the x,y range within the screen */
- if (nyloc > keydp->lastrow) {
- nyloc = keydp->lastrow + 1;
- nxloc = 0;
- }
- else if (nyloc < 0)
- nyloc = 0;
- if (nxloc > keydp->lastcol) {
- nyloc++;
- nxloc = 0;
- }
- else if (nxloc < 0)
- nxloc = 0;
-
- if (nyloc != oyloc || nxloc != oxloc) {
- /* cursor moved, extend selection */
- nomove = FALSE;
-
- if (trackon && !donttrack) {
- InvertRect(&mouserect); /* blank old track rectangle */
- trackon = FALSE;
- }
- if (keydp->selrectset)
- selmove(nyloc, nxloc);
- else {
- selmake(nyloc, nxloc);
- }
- }
- oxloc = nxloc;
- oyloc = nyloc;
- }
- if (nomove && !doubleclick) {
- /* the user wants to move the cursor */
- /* only move the cursor if mouse is in same position */
-
- selreset(keydp);
- if (keydp->connopen) {
- keyputaction(RSLT_YCURS, yloc);
- keyputaction(RSLT_XCURS, xloc);
- }
- }
- selmenuitems(keydp);
- /* fix menu items to reflect whether user has a selection range */
- }
-
- /* set the current selection range given two new points */
-
- selmake(yloc, xloc)
- {
- /* make a fresh selection from the default position;
- start == end */
- keydp->starty = keydp->selystart;
- keydp->startx = keydp->selxstart;
- if (yloc < keydp->selystart) {
- /* selection extends up */
- selset(yloc, xloc, keydp->selystart, keydp->selxstart);
- }
- else if (yloc > keydp->selystart) {
- /* selection extends down */
- selset(keydp->selystart, keydp->selxstart, yloc, xloc);
- }
- else {
- /* selection on one line */
- if (keydp->selxstart < xloc) {
- /* extend right */
- selset(keydp->selystart, keydp->selxstart, yloc, xloc);
- }
- else {
- /* extend left */
- selset(yloc, xloc, keydp->selystart, keydp->selxstart);
- }
- }
- selinvert(keydp);
- keydp->selrectvis = TRUE;
- }
-
- /* Shift-extend the current selection range given two new points */
-
- seladd(yloc, xloc)
- {
- if (yloc < keydp->selystart) {
- /* extend selection up */
- selextend(yloc, xloc, keydp->selystart, keydp->selxstart);
- selset(yloc, xloc, keydp->selyend, keydp->selxend);
- keydp->starty = keydp->selyend;
- keydp->startx = keydp->selxend;
- }
- else if (yloc > keydp->selyend) {
- /* extend selection down */
- selextend(keydp->selyend, keydp->selxend, yloc, xloc);
- selset(keydp->selystart, keydp->selxstart, yloc, xloc);
- keydp->starty = keydp->selystart;
- keydp->startx = keydp->selxstart;
- }
- else {
- /* we shrink the selection up */
- if (keydp->selystart == keydp->selyend) {
- /* just one line, always extend if outside range, else shrink right */
- if (xloc < keydp->selxstart) {
- /* expand selection left */
- selextend(yloc, xloc, keydp->selystart, keydp->selxstart);
- selset(yloc, xloc, keydp->selyend, keydp->selxend);
- keydp->starty = keydp->selyend;
- keydp->startx = keydp->selxend;
- }
- else if (xloc > keydp->selxend) {
- /* expand right */
- selextend(keydp->selyend, keydp->selxend, yloc, xloc);
- selset(keydp->selystart, keydp->selxstart, yloc, xloc);
- keydp->starty = keydp->selystart;
- keydp->startx = keydp->selxstart;
- }
- else {
- /* shrink right */
- selextend(yloc, xloc, keydp->selyend, keydp->selxend);
- selset(keydp->selystart, keydp->selxstart, yloc, xloc);
- keydp->starty = keydp->selystart;
- keydp->startx = keydp->selxstart;
- }
- }
- else if (yloc == keydp->selystart) {
- /* on same line as x, which pair is last? */
- if (xloc > keydp->selxstart) {
- /* shrink selection on the right */
- selextend(yloc, xloc, keydp->selyend, keydp->selxend);
- selset(keydp->selystart, keydp->selxstart, yloc, xloc);
- keydp->starty = keydp->selystart;
- keydp->startx = keydp->selxstart;
- }
- else if (xloc < keydp->selxstart) {
- /* expand selection left */
- selextend(yloc, xloc, keydp->selystart, keydp->selxstart);
- selset(yloc, xloc, keydp->selyend, keydp->selxend);
- keydp->starty = keydp->selyend;
- keydp->startx = keydp->selxend;
- }
- else {
- /* same old selection */
- keydp->starty = keydp->selyend;
- keydp->startx = keydp->selxend;
- return;
- }
- }
- else if (yloc == keydp->selyend) {
- /* on same line as x, which pair is last? */
- if (xloc > keydp->selxend) {
- /* extend selection right */
- selextend(keydp->selyend, keydp->selxend, yloc, xloc);
- }
- else if (xloc < keydp->selxend) {
- /* shrink selection from right */
- selextend(yloc, xloc, keydp->selyend, keydp->selxend);
- }
- selset(keydp->selystart, keydp->selxstart, yloc, xloc);
- keydp->starty = keydp->selystart;
- keydp->startx = keydp->selxstart;
- }
- else {
- /* always shrink bottom */
- selextend(yloc, xloc, keydp->selyend, keydp->selxend);
- selset(keydp->selystart, keydp->selxstart, yloc, xloc);
- keydp->starty = keydp->selystart;
- keydp->startx = keydp->selxstart;
- }
- }
- }
-
- /* dynamically extend the current selection range given two new points--
- centers around beginning point, which is always start or end of selection */
-
- selmove(yloc, xloc)
- {
- if (keydp->starty == keydp->selystart && keydp->startx == keydp->selxstart) {
- /* anchor is at beginning of selection */
- if (yloc < keydp->selystart) {
- /* selection shifts up around anchor */
- selextend(yloc, xloc, keydp->selyend, keydp->selxend);
- selset(yloc, xloc, keydp->selystart, keydp->selxstart);
- }
- else if (yloc > keydp->selyend) {
- /* extend selection down */
- selextend(keydp->selyend, keydp->selxend, yloc, xloc);
- selset(keydp->selystart, keydp->selxstart, yloc, xloc);
- }
- else if (keydp->selystart == keydp->selyend) {
- /* just one line, always extend if outside range, else shrink right */
- if (xloc <= keydp->selxstart) {
- /* selection shifts up around anchor */
- selextend(yloc, xloc, keydp->selyend, keydp->selxend);
- selset(yloc, xloc, keydp->selystart, keydp->selxstart);
- }
- else if (xloc > keydp->selxend) {
- /* expand right */
- selextend(keydp->selyend, keydp->selxend, yloc, xloc);
- selset(keydp->selystart, keydp->selxstart, yloc, xloc);
- }
- else {
- /* in the middle, shrink right end */
- selextend(yloc, xloc, keydp->selyend, keydp->selxend);
- selset(keydp->selystart, keydp->selxstart, yloc, xloc);
- }
- }
- else if (yloc == keydp->selystart) {
- /* on same line as x, which pair is last? */
- if (xloc >= keydp->selxstart) {
- /* shrink selection on the right */
- selextend(yloc, xloc, keydp->selyend, keydp->selxend);
- selset(keydp->selystart, keydp->selxstart, yloc, xloc);
- }
- else if (xloc < keydp->selxstart) {
- /* selection shifts up around anchor */
- selextend(yloc, xloc, keydp->selyend, keydp->selxend);
- selset(yloc, xloc, keydp->selystart, keydp->selxstart);
- }
- else
- /* same old selection */
- return;
- }
- else if (yloc == keydp->selyend) {
- /* on same line as x, which pair is last? */
- if (xloc > keydp->selxend) {
- /* extend selection right */
- selextend(keydp->selyend, keydp->selxend, yloc, xloc);
- }
- else if (xloc < keydp->selxend) {
- /* shrink selection from right */
- selextend(yloc, xloc, keydp->selyend, keydp->selxend);
- }
- else
- /* same old selection */
- return;
- selset(keydp->selystart, keydp->selxstart, yloc, xloc);
- }
- else {
- /* somewhere in the middle of the selection, shrink bottom */
- selextend(yloc, xloc, keydp->selyend, keydp->selxend);
- selset(keydp->selystart, keydp->selxstart, yloc, xloc);
- }
- }
- else if (keydp->starty == keydp->selyend && keydp->startx == keydp->selxend) {
- /* anchor is at end of selection */
- if (yloc < keydp->selystart) {
- /* extend selection up */
- selextend(yloc, xloc, keydp->selystart, keydp->selxstart);
- selset(yloc, xloc, keydp->selyend, keydp->selxend);
- }
- else if (yloc > keydp->selyend) {
- /* shift selection around anchor */
- selextend(keydp->selystart, keydp->selxstart, yloc, xloc);
- selset(keydp->selyend, keydp->selxend, yloc, xloc);
- }
- else if (keydp->selystart == keydp->selyend) {
- /* just one line, always extend if outside range, else shrink right */
- if (xloc <= keydp->selxstart) {
- /* expand left */
- selextend(yloc, xloc, keydp->selystart, keydp->selxstart);
- selset(yloc, xloc, keydp->selyend, keydp->selxend);
- }
- else if (xloc > keydp->selxend) {
- /* shift selection around anchor */
- selextend(keydp->selystart, keydp->selxstart, yloc, xloc);
- selset(keydp->selyend, keydp->selxend, yloc, xloc);
- }
- else {
- /* in the middle, shrink left */
- selextend(keydp->selystart, keydp->selxstart, yloc, xloc);
- selset(yloc, xloc, keydp->selyend, keydp->selxend);
- }
- }
- else if (yloc == keydp->selystart) {
- /* on same line as x, which pair is last? */
- if (xloc > keydp->selxstart) {
- /* shrink selection on the left */
- selextend(keydp->selystart, keydp->selxstart, yloc, xloc);
- }
- else if (xloc < keydp->selxstart) {
- /* expand selection left */
- selextend(yloc, xloc, keydp->selystart, keydp->selxstart);
- }
- else
- /* same old selection */
- return;
- selset(yloc, xloc, keydp->selyend, keydp->selxend);
- }
- else if (yloc == keydp->selyend) {
- /* on same line as x, which pair is last? */
- if (xloc < keydp->selxend) {
- /* shrink left */
- selextend(keydp->selystart, keydp->selxstart, yloc, xloc);
- selset(yloc, xloc, keydp->selyend, keydp->selxend);
- }
- else if (xloc > keydp->selxend) {
- /* shift selection around anchor */
- selextend(keydp->selystart, keydp->selxstart, yloc, xloc);
- selset(keydp->selyend, keydp->selxend, yloc, xloc);
- }
- }
- else {
- /* in middle, shrink top */
- selextend(keydp->selystart, keydp->selxstart, yloc, xloc);
- selset(yloc, xloc, keydp->selyend, keydp->selxend);
- }
- }
- }
-
- /* sets the selection range markers and rectangles */
-
- selset(yloc, xloc, ypos, xpos)
- {
- int midcount;
-
- keydp->selrectset = TRUE;
- keydp->seltopset = FALSE;
- keydp->selmidset = FALSE;
- keydp->selbotset = FALSE;
-
- keydp->selystart = yloc;
- keydp->selyend = ypos;
- keydp->selxstart = xloc;
- keydp->selxend = xpos;
-
- if (yloc == ypos) {
- /* set on a single line */
-
- keydp->seltoprect.top = ypos * keydp->lineheight + keydp->voffset;
- keydp->seltoprect.bottom = keydp->seltoprect.top + keydp->lineheight;
- keydp->seltoprect.left = keydp->selxstart * keydp->fontwidth + keydp->hoffset;
- keydp->seltoprect.right = keydp->seltoprect.left + (keydp->selxend - keydp->selxstart) * keydp->fontwidth;
- keydp->seltopset = TRUE;
- }
- else {
- /* invert the top rectangle */
- keydp->seltoprect.top = yloc * keydp->lineheight + keydp->voffset;
- keydp->seltoprect.bottom = keydp->seltoprect.top + keydp->lineheight;
- keydp->seltoprect.left = xloc * keydp->fontwidth + keydp->hoffset;
- keydp->seltoprect.right = keydp->rightmarg;
- keydp->seltopset = TRUE;
-
- /* invert the mid rectangle if necessary */
- if ( (midcount = ypos - yloc - 1) >= 1) {
- keydp->selmidrect.top = keydp->seltoprect.top + keydp->lineheight + keydp->voffset;
- keydp->selmidrect.bottom = keydp->selmidrect.top + midcount * keydp->lineheight;
- keydp->selmidrect.left = keydp->hoffset;
- keydp->selmidrect.right = keydp->rightmarg;
- keydp->selmidset = TRUE;
- }
-
- /* invert the bottom rectangle */
- keydp->selbotrect.top = ypos * keydp->lineheight + keydp->voffset;
- keydp->selbotrect.bottom = keydp->selbotrect.top + keydp->lineheight;
- keydp->selbotrect.left = keydp->hoffset;
- keydp->selbotrect.right = (xpos) * keydp->fontwidth + keydp->hoffset;
- keydp->selbotset = TRUE;
- }
- }
-
- /* invert the new portions of a selection */
-
- selextend(yloc, xloc, ypos, xpos)
- {
- int midcount;
- Rect trect;
- int txstart;
- int txend;
-
- if (yloc == ypos) {
- /* set on a single line */
- txstart = xloc;
- txend = xpos;
-
- trect.top = ypos * keydp->lineheight + keydp->voffset;
- trect.bottom = trect.top + keydp->lineheight;
- trect.left = txstart * keydp->fontwidth + keydp->hoffset;
- trect.right = trect.left + (txend - txstart) * keydp->fontwidth;
- SETHILITE();
- InvertRect(&trect);
- }
- else {
- /* invert the top rectangle */
- trect.top = yloc * keydp->lineheight + keydp->voffset;
- trect.bottom = trect.top + keydp->lineheight;
- trect.left = xloc * keydp->fontwidth + keydp->hoffset;
- trect.right = keydp->rightmarg;
- SETHILITE();
- InvertRect(&trect);
-
- /* invert the mid rectangle if necessary */
- if ( (midcount = ypos - yloc - 1) >= 1) {
- trect.top = trect.top + keydp->lineheight + keydp->voffset;
- trect.bottom = trect.top + midcount * keydp->lineheight;
- trect.left = keydp->hoffset;
- trect.right = keydp->rightmarg;
- SETHILITE();
- InvertRect(&trect);
- }
-
- /* invert the bottom rectangle */
- trect.top = ypos * keydp->lineheight + keydp->voffset;
- trect.bottom = trect.top + keydp->lineheight;
- trect.left = keydp->hoffset;
- trect.right = (xpos) * keydp->fontwidth + keydp->hoffset;
- SETHILITE();
- InvertRect(&trect);
- }
- }
-
-
- selinvert(twp)
- struct winds * twp;
- {
- if (keydp->seltopset) {
- SETHILITE();
- InvertRect(&twp->seltoprect);
- }
- if (keydp->selmidset) {
- SETHILITE();
- InvertRect(&twp->selmidrect);
- }
- if (keydp->selbotset) {
- SETHILITE();
- InvertRect(&twp->selbotrect);
- }
- }
-
- selreset(twp)
- struct winds * twp;
- {
- if (twp->selrectvis) {
- selinvert(twp);
- }
- twp->selrectset = FALSE;
- twp->selrectvis = FALSE;
- twp->seltopset = FALSE;
- twp->selmidset = FALSE;
- twp->selbotset = FALSE;
- twp->selystart = 0;
- twp->selxstart = 0;
- twp->selyend = 0;
- twp->selxend = 0;
- }
-
-
- /* work the controls at the top of the emulator screen */
-
- doq1controls(where)
- Point * where;
- {
- Point thepoint;
- ControlHandle whichcontrol;
- struct fontsave ofont;
-
- if (!keydp->connopen)
- return;
-
- thepoint.h = where->h;
- thepoint.v = where->v;
-
- if (FindControl(pass(thepoint), keydp->emwindow, &whichcontrol)) {
- savefont(&ofont);
- if (TrackControl(whichcontrol, pass(thepoint), (ProcPtr) NULL)) {
- if (keydp->ibm_keymode) {
- switch ( (int) (*whichcontrol)->contrlRfCon) {
- case Q1BUT1: {
- keyputaction(RSLT_PFKY,ENTER);
- break;
- }
- case Q1BUT2: {
- keyputaction(RSLT_PFKY,PA1);
- break;
- }
- case Q1BUT3: {
- keyputaction(RSLT_PFKY,PA2);
- break;
- }
- case Q1BUT4: {
- keyputaction(RSLT_PFKY,CLEAR);
- break;
- }
- case Q1BUT5: {
- /* insert */
- keyputaction(RSLT_LCAC,INSRT);
- break;
- }
- case Q1BUT6: {
- /* reset */
- sendReset();
- break;
- }
- case Q1BUT7: {
- /* home */
- keyputaction(RSLT_MVCR,HOME);
- break;
- }
- case Q1BUT8: {
- /* erase input */
- keyputaction(RSLT_LCAC,INPUT_ERASE);
- /* TODO not defined in 7171keys document */
- break;
- }
- case Q1BUT9: {
- keyputaction(RSLT_LCAC,ERASE_EOF);
- /* erase to end of field */
- break;
- }
- case Q1BUT10: {
- keyputaction(RSLT_PFKY,PA3);
- /* PA3 */
- break;
- }
- case Q1BUT11: {
- keyputaction(RSLT_LCAC,DEL_CHAR);
- /* delete char */
- break;
- }
- }
- }
- else {
- switch ( (int) (*whichcontrol)->contrlRfCon) {
- case Q1CR: {
- /* CR */
- keyputaction(RSLT_ASCI, CR);
- break;
- }
- case Q1LF: {
- /* send linefeed */
- keyputaction(RSLT_ASCI, LF);
- break;
- }
- case Q1ESC: {
- /* send escape */
- keyputaction(RSLT_ASCI, ESC);
- break;
- }
- case Q1CTLS: {
- /* send ^S */
- keyputaction(RSLT_ASCI, CTLS);
- HiliteControl(keydp->q1controls[Q1CTLS], 1);
- break;
- }
- case Q1CTLQ: {
- /* send ^Q */
- keyputaction(RSLT_ASCI, CTLQ);
- HiliteControl(keydp->q1controls[Q1CTLS], 0);
- break;
- }
- case Q1DEL: {
- /* Delete */
- keyputaction(RSLT_ASCI, DELETE);
- break;
- }
- case Q1BREAK: {
- /* send BREAK */
- sendBreak();
- break;
- }
- case Q1CTLC: {
- /* ^C */
- keyputaction(RSLT_ASCI, CTLC);
- break;
- }
- case Q1CTLU: {
- /* ^U */
- keyputaction(RSLT_ASCI, CTLU);
- break;
- }
- case Q1IC: {
- /* ^U */
- keyputaction(RSLT_ASCI, ESC);
- keyputaction(RSLT_ASCI, 'O');
- keyputaction(RSLT_ASCI, 'w');
- break;
- }
- case Q1DC: {
- /* ^U */
- keyputaction(RSLT_ASCI, ESC);
- keyputaction(RSLT_ASCI, 'O');
- keyputaction(RSLT_ASCI, 'y');
- break;
- }
- }
- }
- }
- restorefont(&ofont);
- }
- }
-
-
- /*
- * when a third quadrant button is pushed, this routine is called to
- * send a string to the host.
- */
-
- doq3controls()
- {
- register char * charp;
- long ticks;
- short shift = FALSE;
-
- if (!keydp->connopen)
- return(-1);
-
- if (!q3button)
- return(-1);
-
- FillRoundRect(&q3highrect, BUT3HIGH, BUT3WIDE, gray);
-
- if (keydp->ibm_keymode) {
- if (myEvent.modifiers & shiftKey)
- /* do a shift */
- keyputaction(RSLT_PFKY, PFSHIFT);
- keyputaction(RSLT_PFKY, PF1 + q3button - 1);
- }
- else {
- if (myEvent.modifiers & shiftKey)
- /* do a shift */
- shift = 12;
-
- if (keydp->termtype == TERM_VT100
- || keydp->termtype == TERM_VT102
- || keydp->termtype == TERM_VT220
- ) {
- /* vt100 strings */
- if (shift && q3button > 6) {
- /* one of the 6 VT102 function keys */
- sendvt102key(q3vtcontrols[q3button + shift - 1]);
- }
- else
- sendvtkeyfunc(q3vtcontrols[q3button + shift - 1]);
- }
- else {
- /* send H19 control string */
- keyputaction(RSLT_ASCI, 0x1B);
- keyputaction(RSLT_ASCI, q3controls[q3button - 1]);
- }
- }
- Delay( (long) 10, &ticks);
- FillRoundRect(&q3highrect, BUT3HIGH, BUT3WIDE, black);
- blanklabels();
- }
-
-
-
- /* this routine uses the same logic used for drawing the left hand controls
- to check to see if they should be highlighted
- */
-
- check3controls(mouseloc, shift)
- Point mouseloc;
- int shift;
- {
- register int count;
- Rect fillrect;
-
- fillrect.top = 0;
- fillrect.left = -12;
- fillrect.bottom = 21; /* bottom - top == 20, * 12 boxes == height of window */
- fillrect.right = -2; /* was -4 */
-
- for (count = 1; count < 13; count++) {
- if (PtInRect(pass(mouseloc), &fillrect)) {
- if (q3button) {
- if (q3highrect.top == fillrect.top) {
- /* don't bother filling it again */
- #ifdef WORONACURSOR
- if (shift != labelshift)
- SetCursor(*GetCursor(127 + count + shift));
- /* update the numbered cursor */
- #endif
- return;
- }
- else if (q3highrect.top != -1) {
- /* the old one needs to be set back to gray */
- FillRoundRect(&q3highrect, (short) BUT3HIGH, (short) BUT3WIDE, gray);
- FrameRect(&q3highrect);
- }
- }
- q3button = count;
- q3highrect.top = fillrect.top;
- q3highrect.left = fillrect.left + 3;
- q3highrect.bottom = fillrect.bottom;
- q3highrect.right = fillrect.right - 2;
- FillRoundRect(&q3highrect, (short) BUT3HIGH, (short) BUT3WIDE, black);
-
- #ifdef WORONACURSOR
- SetCursor(*GetCursor(127 + count + shift));
- /* put up a numbered cursor to show which PF is activated */
- #endif
- return;
- }
- if (count % 3) {
- fillrect.top += q3conth;
- fillrect.bottom += q3conth;
- }
- else {
- fillrect.top += q3conth + q3contskip;
- fillrect.bottom += q3conth + q3contskip;
- }
- }
- #ifdef WORONACURSOR
- if (!q3button)
- /* make the cursor an arrow if no button has been selected yet */
- #endif
- SetCursor(&arrow);
- }
-
-
- reset3controls()
- {
- if (q3button) {
- FillRoundRect(&q3highrect, (short) BUT3HIGH, (short) BUT3WIDE, gray);
- FrameRect(&q3highrect);
-
- q3highrect.top = -1;
- q3button = 0;
- }
- }
-
-
- /* draw labels to the right of the buttons in the third quadrant */
-
- q3labels(shift)
- int shift; /* + 12 when Shift key down */
- {
- Point penloc;
- int count;
- int length; /* length of a string */
- int maxlength; /* length of the longest string */
- int asciishift;
- struct fontsave ofont;
-
- maxlength = 0;
-
- if (q3labdrawn) {
- if (shift == labelshift)
- /* already displayed correctly */
- return(0);
- }
- /* first find the longest string to size the box... */
- asciishift = (keydp->ibm_keymode ? 0 : 24);
- /* use VT100 labels if in ASCII mode */
-
- if (q3labdrawn) {
- /* reset clip so we can draw in box */
- ClipRect(&boxrect);
- }
- else {
- emwdeactivate(); /* will increment bkrd_act */
- InvertRect(&keydp->qmarkrect);
-
- for (count = 0; count < 24; count++) {
- if (q3strings[count + asciishift] == NULL)
- /* make sure the string exists! */
- continue;
- length = strlen(q3strings[count + asciishift]);
- if (length > maxlength)
- maxlength = length;
- }
- boxrect.top = -4;
- boxrect.left = -2;
- boxrect.bottom = 285;
- boxrect.right = maxlength * 6 + 20;
- /* set to length of largest string +20--assuming fixed-width font */
- }
-
- EraseRect(&boxrect);
- FrameRect(&boxrect);
-
- penloc.h = 10;
- penloc.v = 15;
-
- savefont(&ofont);
- for (count = 1; count < 13; count++) {
- if (q3strings[count + shift + asciishift] == NULL)
- /* make sure the string exists! */
- continue;
- MoveTo(penloc.h, penloc.v);
- DrawText(q3strings[count + shift + asciishift - 1], (short) 0,
- strlen(q3strings[count + shift + asciishift - 1]) );
- if (count % 3) {
- penloc.v += 22;
- }
- else {
- penloc.v += 29;
- }
- }
- restorefont(&ofont);
-
- if (!q3labdrawn) {
- /* now set the clip region to exclude boxrect so no drawing can occur in box */
- /* NB if bkrd_act does not disable cursor blink turds will result */
-
- GetClip(emclip);
- RectRgn(q3clip, &boxrect);
- DiffRgn(emclip, q3clip, q3clip);
- SetClip(q3clip);
- }
- else
- SetClip(q3clip); /* reset clip */
-
- q3labdrawn = keydp->emwindow;
- }
-
-
- /* blank the pf key labels in the 3rd quadrant */
-
- blanklabels()
- {
- GrafPtr oport;
-
- if (q3labdrawn) {
- GetPort(&oport);
- SetPort(q3labdrawn);
-
- --bkrd_act;
- SetClip(emclip); /* restore portRect clip */
- EraseRect(&boxrect);
- InvertRect(&keydp->qmarkrect);
- InvalRect(&boxrect);
-
- SetPort(oport);
- q3labdrawn = NULL;
- }
- }
-
-
-
- showq3buttons()
- {
- Rect fillrect;
- int count;
-
- fillrect.top = 0;
- fillrect.left = -9;
- fillrect.bottom = 21;
- fillrect.right = -4;
-
- for (count = 1; count < 13; count++) {
- FillRoundRect(&fillrect, (short) BUT3HIGH, (short) BUT3WIDE, gray);
- FrameRect(&fillrect);
- if (count % 3) {
- fillrect.top += q3conth;
- fillrect.bottom += q3conth;
- }
- else {
- fillrect.top += q3conth + q3contskip;
- fillrect.bottom += q3conth + q3contskip;
- }
- }
- }
-
-
- /* the following are different because the use emdp rather than keydp */
-
-
- /* highlight the iconwindow contents to show that new data has arrived */
-
- emalert()
- {
- GrafPtr oldport;
- Rect destrect;
-
- destrect.top = 0;
- destrect.left = 0;
- destrect.bottom = 33;
- destrect.right = 46;
-
- if (!emdp->iconhigh && emdp->icon_up) {
- GetPort(&oldport);
- SetPort(emdp->iconwindow);
- SETHILITE();
- InvertRect(&destrect);
- emdp->iconhigh = TRUE;
- SetPort(oldport);
- }
- }
-
-
- /* TODO is DANGEROUS assumes keywindow is active */
-
-
- /* light up INSERT button when in IBM mode */
-
- showinsert()
- {
- struct fontsave ofont;
-
- if (emdp->emwindow == NULL)
- return;
-
- if (emdp->ibm_keymode && emdp->q1controls[Q1BUT5] != NULL) {
- savefont(&ofont);
- HiliteControl(emdp->q1controls[Q1BUT5], (short) 1);
- emdp->controlschanged = TRUE;
- copytoprect(emwindow);
- restorefont(&ofont);
- }
- }
-
-
- /* un-highlight INSERT button when in IBM mode */
-
- clrinsert()
- {
- struct fontsave ofont;
-
- if (emdp->emwindow == NULL)
- return;
-
- if (emdp->ibm_keymode && emdp->q1controls[4] != NULL) {
- savefont(&ofont);
- HiliteControl(emdp->q1controls[4], (short) 0);
- emdp->controlschanged = TRUE;
- copytoprect(emwindow);
- restorefont(&ofont);
- }
- }
-
-
-